﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fortuitus.Core;

namespace ConsoleTestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            //TestMaskedVectorViewMemory();
            //TestCorrelationPerformance();

          //  var p = Statistics.F_Pvalue(2.45, 3, 5);
            TestAnova();
            Console.ReadLine();

        }

        private static void TestAnova()
        {
            IVector a = new Vector(new double[] { 6, 8, 4, 5, 3 });
            IVector b = new Vector(new double[] { 8, 12, 9, 11, 6, 8,34 });
            IVector c = new Vector(new double[] { 13, 9, 11, 8, 7, 12 });
            List<IVector> lst = new List<IVector>();
            lst.Add(a);
            lst.Add(b);
            lst.Add(c);

            int df1;
            int df2;

            double F = Statistics.OneWayANOVA(lst, out df1, out df2);
            var p = Statistics.F_Pvalue(F, df1, df2);
        }

        private static void TestCorrelationPerformance()
        {
            List<double> a = new List<double>();
            List<double> b = new List<double>();
            Random rand = new Random();
            for (int i = 0; i < 100; i++)
            {
                a.Add(rand.NextDouble());
                b.Add(rand.NextDouble());
            }
            IVector x = new Vector(a);
            IVector y = new Vector(b);

            DateTime start;

            start = DateTime.Now;
            for (int i = 0; i < 100000; i++)
            {
                Statistics.PearsonCorrelationCoefficient(x, y);
            }
            TimeSpan pearsonTime = DateTime.Now - start;

            start = DateTime.Now;
            for (int i = 0; i < 100000; i++)
            {
                Statistics.SpearmanCorrelationCoefficient(x, y);
            }
            TimeSpan spearmanTime = DateTime.Now - start;

            Console.WriteLine("Pearson: {0}", pearsonTime);
            Console.WriteLine("Spearman: {0}", spearmanTime);
        }

        private static void TestMaskedVectorViewMemory()
        {
            List<double> numbers = new List<double>();
            for (int i = 0; i < 10000000; i++)
            {
                numbers.Add(i);
            }

            List<IVector> test = new List<IVector>();
            IVector baseVector = new Vector(numbers);
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 10000; j++)
                {
                    IVectorView bla = new MaskedVectorView(baseVector, new int[] { 22, 44, 66, 88, 99, 11, 23 });
                    // IVector bla = new Vector(new double[] { 22, 44, 66, 88, 99, 11, 23 });
                    test.Add(bla);
                }
                Console.WriteLine(i);
            }

            var memAvailable = GC.GetTotalMemory(false);
            Console.WriteLine("After allocations: {0:N0}", memAvailable);
            Console.ReadLine();
        }
    }
}
